package GUI;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import MessagePacks.MessagePack;
import MessagePacks.UpdatePack;

/**
 *@author Juan Alapin - 324507516
 *@author Giora Yaffe - 036551281
 *@author Shachar Gritzman - 300174026
 *@author Nir Porat - 021515580
*/

public class TesterFailReport extends MasterGUI {

	private static final long serialVersionUID = 1L;
	private MainGUI maingui;
	private UpdatePack updatePhs;
	private UpdatePack fail,status;
	private JTextArea FailReport;
	private JButton btnSend;
	
	public TesterFailReport (MainGUI mainGui) {
		super(mainGui);
		this.maingui=mainGui;
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 884, 40);
		getContentPane().add(panel);
		
		JLabel lblTesterFailReport = new JLabel("Tester Fail Report");
		lblTesterFailReport.setFont(new Font("Dialog", Font.BOLD, 16));
		panel.add(lblTesterFailReport);
		
		JLabel lblFailReportDetails = new JLabel("Fail Report Details");
		lblFailReportDetails.setHorizontalAlignment(SwingConstants.RIGHT);
		lblFailReportDetails.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblFailReportDetails.setBounds(103, 128, 162, 23);
		getContentPane().add(lblFailReportDetails);
		
		setBtnSend();
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(275, 135, 310, 265);
		getContentPane().add(scrollPane);
		
		FailReport = new JTextArea();
		scrollPane.setViewportView(FailReport);
	}		
	public void updatePhase3(){
		updatePhs = new UpdatePack(MessagePack.updatePhase);
		updatePhs.setPhaseNum(3);
		updatePhs.setProcId(maingui.process.getprocessID());
	//	updatePhs.setResponOk(1);
		maingui.client.handleMessageFromClientUI(updatePhs);
	}
	public void EnterFailReport() {
		fail = new UpdatePack(MessagePack.testfailreport);
		fail.setTestfail(FailReport.getText());
		fail.setProcId(maingui.process.getprocessID());
		maingui.client.handleMessageFromClientUI(fail);
	}
	public void updateStatus(){
		status = new UpdatePack(MessagePack.updateStatus);
		status.setStatus("waiting for approval");
		status.setProcId(maingui.process.getprocessID());
		maingui.client.handleMessageFromClientUI(status);
	}
	

	public JButton getBtnSend() {
		return btnSend;
	}
	public void setBtnSend() {
		btnSend = new JButton("Send");
		btnSend.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				updatePhase3();
				EnterFailReport();
				updateStatus();
				close();
				TesterScreen TS = new TesterScreen(maingui);
				TS.setVisible(true);
			}
		});
		btnSend.setBounds(388, 431, 89, 23);
		getContentPane().add(btnSend);
	}
}